package com.itboye.hutouben.adapter;

import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.itboye.hutouben.R;
import com.itboye.hutouben.activity.mysetting.ActivityWeiXiuXiangqing;
import com.itboye.hutouben.base.MyApplcation;
import com.itboye.hutouben.bean.WeiXiuiJiLuBean;
import com.itboye.hutouben.util.TimeFormat;

import java.util.ArrayList;
import java.util.List;

/**
 * 维修记录
 */
public class WeiXiuRecordAdapter extends BaseAdapter {
    Activity context;
    List<WeiXiuiJiLuBean.ListInfo> list;

    public WeiXiuRecordAdapter(Activity context, List<WeiXiuiJiLuBean.ListInfo> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        if (list.size() <= 0) {
            return 0;
        } else {
            return list.size();
        }

    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        viewHolder holder = null;
        if (convertView == null) {
            holder = new viewHolder();
            convertView = LayoutInflater.from(MyApplcation.ctx).inflate(R.layout.item_weixiu, null);
            holder.tvTimeData = (TextView) convertView.findViewById(R.id.tvTimeData);
            holder.tvDriver = (TextView) convertView.findViewById(R.id.tvDriver);

            holder.tvinformation = (TextView) convertView.findViewById(R.id.tvinformation);
            holder.tvMaintenanceCosts = (TextView) convertView.findViewById(R.id.tvMaintenanceCosts);
            holder.tvMaterialConst = (TextView) convertView.findViewById(R.id.tvMaterialConst);
            holder.weixiu_tv = (TextView) convertView.findViewById(R.id.weixiu_tv);
            holder.tvOk = (TextView) convertView.findViewById(R.id.tvOk);
            convertView.setTag(holder);
        } else {
            holder = (viewHolder) convertView.getTag();
        }
        final ArrayList<String> imgs =new ArrayList<String>();
        imgs.add(list.get(position).getImages());
        holder.tvOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(context, ActivityWeiXiuXiangqing.class);
                intent.putExtra("WeiXiu1",list.get(position).getPrice());
                intent.putExtra("WeiXiu2", list.get(position).getStuff_price());
                intent.putExtra("WeiXiu3", list.get(position).getRepair_price());
                intent.putExtra("WeiXiu4",list.get(position).getDetail());
                intent.putExtra("WeiXiu5",list.get(position).getImages());
                intent. putStringArrayListExtra("info",imgs);
                context.startActivity(intent);

            }
        });
        holder.tvTimeData.setText(TimeFormat.DateFormat(list.get(position).getCreate_time()));//时间
        if(list.get(position).getWorker_realname().equals("")){
            holder.tvDriver.setText("匿名");//接单师傅
        }else{
            holder.tvDriver.setText(list.get(position).getWorker_realname());//接单师傅
        }
        holder.tvinformation.setText(list.get(position).getWorker_mobile());//联系方式
        holder.tvMaintenanceCosts.setText("¥:"+Double.parseDouble(list.get(position).getRepair_price())/100+"");//维修费用
        holder.tvMaterialConst.setText("¥:"+Double.parseDouble(list.get(position).getStuff_price())/100+"");//材料费用
        holder.weixiu_tv.setText(list.get(position).getOrder_code());//维修单号
        return convertView;
    }


    class viewHolder {
        TextView tvTimeData;
        TextView tvDriver;
        TextView tvinformation;
        TextView tvMaintenanceCosts;
        TextView tvMaterialConst;
        TextView weixiu_tv, tvOk;
    }

}
